﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Heaven.Texturing.Importers.DirectDraw
{
    class LayerConverter
    {
        #region

        LayerFormat format = LayerFormats.A8R8G8B8;
        byte[] data;
 
        #endregion

        #region

        public LayerFormat Format
        {
            get { return format; }
        }

        public byte[] Data
        {
            get
            {
                return data;
            }
        }

        #endregion

        #region

        public LayerConverter(byte[] data, PixelFormat pixelFormat)
        {
            if (((pixelFormat.Flags & Header.DDPF_RGB) != 0) && (((pixelFormat.Flags & Header.DDPF_ALPHA) != 0)||((pixelFormat.Flags & Header.DDPF_ALPHAPIXELS) != 0)))
            {
                this.data = data;
            }
            else if ((pixelFormat.Flags & Header.DDPF_RGB) != 0)
            {
                int length = data.Length / 3;
                this.data = new byte[length * 4];
                for (int i = 0; i < length; i++)
                {
                    this.data[i * 4 + 0] = 255;
                    this.data[i * 4 + 1] = data[i * 3 + 0];
                    this.data[i * 4 + 2] = data[i * 3 + 1];
                    this.data[i * 4 + 3] = data[i * 3 + 2];
                }
            }
            else throw new ApplicationException("");

        }

        #endregion
    }
}
